<div class="block" id="payment-balance">
	<div class="block-title">
		Unpaid Balance
	</div>
	<div class="block-body">
		<h4>Below is a breakdown of your unpaid balance:</h4>
		<?php 
		$this->widget('zii.widgets.grid.CGridView', array(
				'id'=>'report-grid',
			 	'summaryText' => '',
				'dataProvider'=>$dataProvider,
				'columns'=>array(
					array('name' => 'Website', 'value' => '$data->website'),
					array('name' => 'Date', 'value' => '$data->year."-".$data->month'),
					array('name' => 'Commission', 'value' => '"\$".$data->commission'),
					//'amount'
					//'Members',
					//'Amount',
				),
			));
		?>
		<p>
			If your unpaid balance is greater than <span style="color: blue;">$<?php echo Yii::app()->params['minBalanceForPay'] ?></span>,
			click on "Send Payment Request" below to have your payment sent to you immediately or, 
			otherwise, QpidAffiliate will automatically transfer your funds on the 20th of this month.
		</p>
		
		<p>
			<?php
			$disabled = '';
			if (PaymentRequest::hasSent(Yii::app()->user->id) || $balance < Yii::app()->params['minBalanceForPay']) {
				$disabled = 'disabled="disable"';
			}
			?>
			<input value="Send Payment Request" id="send-payment-request" type="button" <?php echo $disabled;?> />
			<span id="warning">
				<strong>Warning</strong>: 
				Your payment details are incomplete. Please <a href="<?php echo $this->createUrl('owner/account/update?fields=payment')?>">click here</a> to complete so that you can receive your payments.
			</span>
			<br class="clear" />
		</p>
		
		
		<p class="have-sent-msg" <?php if (!PaymentRequest::hasSent(Yii::app()->user->id)) echo 'style="display:none"';?>>
			你的付款申请已经发出，我们会在X个工作日之内将佣金支付给你，请等待......
		</p>
		
		<script>
		<?php
		$total = array_pop($dataProvider->data);
		echo "var amount={$total->commission};"; 
		?>
		$(function(){
			$("#send-payment-request").click(function(){
				$.post("/index.php/owner/payment/request", {amount: amount, ajax: "payment-request"}, function(data){
					if (data.result) {
						$(".have-sent-msg").show();
					}
				}, "json");
			})
		})
		</script>
	</div>
</div>